<template>
	<view class="container">
	    <view class="header">
	        <view>
	            <view class="pic">
	                <image :src="avatarUrl"></image>
	                <view class="userinfo">
	                    <view style="font-size:15px;">{{nickName}}</view>
	                    <view class="headerrule"> 消息中心</view>
	                </view>
	            </view>
	        </view>
	        <view>
	            <view class="opencard" v-if="role == 1">
	                <image src="/static/img1/user.png"></image>用户
	            </view>
	            <view class="opencard" v-if="role == 2">
	                <image src="/static/img1/vip.png"></image>会员
	            </view>
	            <view class="opencard" v-if="role == 3">
	                <image src="/static/img1/jg.png"></image>机构
	            </view>
	            <view class="opencard" v-if="role == 4">
	                <image src="/static/img1/dls.png"></image>合伙人
	            </view>
	        </view>
	    </view>
	
	
	
	    <view class="list" v-if="role == 2">
	        <view @click="jumpCenter('/pages/message/online')" class="item">
	            <image src="/static/img1/comm.jpg"></image>
	            <text>正在沟通</text>
	            <view v-if="count.onlineCount" class="num">{{count.onlineCount}}</view>
	        </view>
	        <view @click="jumpCenter('/pages/message/see')" class="item">
	            <image src="/static/img1/phone.jpg"></image>
	            <text>电话查看请求</text>
	            <view v-if="count.phoneCount" class="num">{{count.onlineCount}}</view>
	        </view>
	        <view @click="jumpCenter('/pages/message/interview')" class="item">
	            <image src="/static/img1/mianshi.jpg"></image>
	            <text>面试通知</text>
	            <view v-if="count.interCount" class="num">{{count.onlineCount}}</view>
	        </view>
	        <view @click="jumpCenter('/pages/message/delivery')" class="item">
	            <image src="/static/img1/job.jpg"></image>
	            <text>我的求职</text>
	            <view v-if="count.deliveryCount" class="num">{{count.onlineCount}}</view>
	        </view>
	    </view>
	
	    <view class="list" v-if="role == 3">
	        <view @click="jumpCenter('/pages/message/online')" class="item">
	            <image src="/static/img1/comm.jpg"></image>
	            <text>正在沟通</text>
	            <view class="num">{{count.onlineCount}}</view>
	        </view>
	        <view @click="jumpCenter('/pages/message/see')" class="item">
	            <image src="/static/img1/phone.jpg"></image>
	            <text>电话查看请求</text>
	            <view class="num">{{count.phoneCount}}</view>
	        </view>
	        <view @click="jumpCenter('/pages/message/interview')" class="item">
	            <image src="/static/img1/mianshi.jpg"></image>
	            <text>我的邀约</text>
	            <view class="num">{{count.interCount}}</view>
	        </view>
	        <view @click="jumpCenter('/pages/message/delivery')" class="item">
	            <image src="/static/img1/job.jpg"></image>
	            <text>收到的简历</text>
	            <view class="num">{{count.deliveryCount}}</view>
	        </view>
	    </view>
	</view>
</template>

<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			avatarUrl: '/static/qrcode.jpg',
			nickName:'',
			role:0,
			count:[]
		}
	},
	onShow:function() {
		this.login()
	},
	methods: {
		login:function(){
			if(!uni.getStorageSync('uid')){
				//没有缓存 跳转授权页面
				uni.navigateTo({
					url:'/pages/index/guide'
				});
			}else{
				this.avatarUrl = uni.getStorageSync('avatarUrl'),
				this.nickName = uni.getStorageSync('nickName'),
				this.role = uni.getStorageSync('role')
				//验证手机号码是否存在
				this.checkphone();
			}
		},
		//查询手机号  是否注册
		checkphone:function(){
			var data = {
				'uid':uni.getStorageSync('uid')
			}
			var that = this
			request({
				url: 'member/phone',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code !== 1){
						uni.navigateTo({
							url:'/pages/index/phone'
						})
						return;
					}
					uni.showLoading({
						title: '加载中'  
					});
					that.getCount();
				}
			})
		},
		getCount:function(){
			var that = this
			var data = {'uid':uni.getStorageSync('uid')}
			request({
				url: 'information/center',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.hideLoading()
						that.count = res.data.data
					}
				}
			})
		},
		jumpCenter:function(url){
			uni.navigateTo({
			  url:url
			})
		},
		jump:function(url){
			// uni.showToast({
			// 	title: '此功能正在开发,请前往小程序查看消息!!!',
			// 	icon: "none", 
			// 	position:'bottom',
			// });
			//console.log(url)
			plus.share.getServices(
				res => {
					let sweixin = null;
					for (let i in res) {
						if (res[i].id == 'weixin') {
							sweixin = res[i];
						}
					}
					//唤醒微信小程序
					if (sweixin) {
						sweixin.launchMiniProgram({
							id: 'gh_42fb5eed1670', //
							type: 0, //小程序版本  0-正式版； 1-测试版； 2-体验版。
							path: 'pages/index/index' //小程序的页面,用传的参数在小程序接值判断跳转指定页面
						});
					}
				}
			);
		}
	}
}
</script>

<style scoped>
	@import url("./css/index.css");
</style>
